﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;

/// <summary>
/// Tool_kitcs 的摘要描述
/// </summary>
public class Tool_kitcs
{

  const string SERVICE_ID = "SurveyDesign";
  const string Password = "kBnjhArF48LwdWEGYw2g";
  const string URL = "http://ios.ccp.com.tw/Chris/ccpsip/Robot/get_user_info.ashx";

  //回傳USER資訊
  public static string GetUserInfo(
    string SIP_Num,
    string MobileNum) {
    string fullResponse, CustomName = "";
    HttpWebResponse webResponse = null;
    try {
      Dictionary<string, object> postParameters = new Dictionary<string, object>();
      postParameters.Add("SERVICE_ID", SERVICE_ID);
      postParameters.Add("Password", Password);
      postParameters.Add("SIP_Num", SIP_Num);
      postParameters.Add("MobileNum", SIP_Num);

      // Create request and receive response
      webResponse = FormUpload.MultipartFormDataPost(URL,
        "Someone",
        postParameters);

      // Process responses
      StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
      fullResponse = responseReader.ReadToEnd();
      JObject jo = JObject.Parse(fullResponse);
      CustomName = jo["CustomName"].ToString();
      return CustomName;
    }
    catch {
      fullResponse = "error";
    }
    finally {
      webResponse.Close();
    }
    return fullResponse;
  }
}